﻿using _03_View_Model_MVVM_Basics.Directory.Data;
using System.IO;
using System.Windows;

namespace _03_View_Model_MVVM_Basics.Directory
{
	public static class DirectoryStructure
	{
		public static string GetName(string path)
		{
			if (string.IsNullOrEmpty(path)) return "";
			return path.Split("\\").LastOrDefault() ?? path;
		}

		public static List<DirectoryItem> GetDrives()
		{
			return System.IO.Directory.GetLogicalDrives().Select(drive => new DirectoryItem()
			{
				Type = DirectoryItemType.Drive,
				FullPath = drive
			}).ToList();
		}

		public static List<DirectoryItem>? GetDirectories(string? fullPath)
		{
			if (string.IsNullOrEmpty(fullPath)) return null;
			return System.IO.Directory.GetDirectories(fullPath).Select(folder => new DirectoryItem
			{
				Type = DirectoryItemType.Folder,
				FullPath = folder
			}).ToList();
		}

		public static List<DirectoryItem>? GetFiles(string? fullPath)
		{
			if (string.IsNullOrEmpty(fullPath)) return null;
			return System.IO.Directory.GetFiles(fullPath).Select(file => new DirectoryItem
			{
				Type = DirectoryItemType.File,
				FullPath = file
			}).ToList();
		}
	}
}
